import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';


@Injectable()
export class HomeService {

    articleRecommend: any;//推荐文章，包含分页对象
    page: any;//
    search: string;//搜索关键词
    list: any;//列表数据
    scrollTop:number;//记录滚动条的位置

    constructor(
        private http: HttpClient
    ) {
        this.articleRecommend = {
            current_page: 1,
            data: [],
            last_page: 0//最后一页
        };
        this.page = [];
        this.search = '';
        this.list = [];
        this.scrollTop=0;
    }

    //首页数据
    home(): Observable<any> {
        return this.http.request('get', 'home');
    }

    //顶部菜单
    getNavs(): Observable<any> {
        return this.http.request('get', 'navs');
    }

    //推荐文章
    getArticleRecommend(body: any): Observable<any> {
        return this.http.request('get', 'articleRecommend', {body: body});
    }

    //最新文章和点击排行
    getArticleNewAndClick(): Observable<any> {
        return this.http.request('get', 'articleNewAndClick');
    }
}
